package name.jiaosha.air.user.controller;

import java.util.List;

import name.jiaosha.air.OperateTip;
import name.jiaosha.air.company.domain.Company;
import name.jiaosha.air.company.service.ICompanyService;
import name.jiaosha.air.user.domain.LoginUser;
import name.jiaosha.air.user.service.IUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ali8ba.common.AliUtil;
@Repository("loginUserController")
public class LoginUserController {
	@Autowired
	private IUserService userService;
	
	@Autowired
	private ICompanyService companyService;

	public List<LoginUser> getMyLoginUserList() {

		return userService.getLoginUserListByComId(1);
	}
	public OperateTip create(LoginUser loginUser){
		
		
		loginUser.setPassword(AliUtil.MD5(loginUser.getPassword()));
		Company company = companyService.getCompanyById(1);
		loginUser.setCompany(company);
		userService.createLoginUser(loginUser);
		OperateTip tip = new OperateTip("1", "操作成功");
		return tip;
	}
	
	
	public LoginUser getLoginUserById(int id){
		
		return userService.getLoginUserById(id);
		
	}
	public OperateTip update(LoginUser loginUser){
		
		LoginUser user=userService.getLoginUserById(loginUser.getId());
		
		if(loginUser.getPassword()!=null && loginUser.getPassword().length()>=6){
			
			user.setPassword(AliUtil.MD5(loginUser.getPassword()));
		}
		userService.updateLoginUser(user);
		OperateTip tip = new OperateTip("1", "操作成功");
		return tip;
	}
}
